package 语雀题目21至55;

/**
 * ClassName: 输出指定位数的水仙花数答案
 * Package: 语雀21至40
 * Description:
 *
 * @Author fjorid
 * @Create 2025/1/6 18:52
 * @Version 1.0
 */
import java.util.Scanner;

class NarcissusNumber {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要计算的水仙花数的位数");
        int digit = scan.nextInt();
        int lowerBound = (int) Math.pow(10, digit - 1);
        int upperBound = (int) Math.pow(10, digit) - 1;
        int sum = 0;

        for (int i = lowerBound; i <= upperBound; i++) {
            int original = i;
            sum = 0;
            while (original > 0) {
                int temp = original % 10;
                int power = 1;
                for (int j = 1; j <= digit; j++) {
                    power *= temp;
                }
                sum += power;
                original /= 10;
            }
            if (sum == i) {
                System.out.println(i + "是水仙花数");
            }
        }
        scan.close();
    }
}